<html>
<head>
    <meta charset="UTF-8">
    <title>结算查询</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/bass.css"/>
    <link rel="stylesheet" href="../../css/air/arrPay.css"/>
    <style>
        .layui-input-block{
            margin-left: 80px !important;
        }
        .left{
            margin-left: 20px;
        }
    </style>
</head>

<body>
<div class="body contractDay">
    <header class="layui-nav" id="headerTop"></header>
    <div class="left_muen" id="left_menu"></div>
    <div class="content_body contractDay">
        <p class="content_title">气量管理&nbsp;&nbsp;>&nbsp;&nbsp;结算查询</p>

        <div class="content_seach">
            <div class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label">日期</label>

                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="startTime" id="test31" placeholder="请输入起始日期">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="endTime" id="test32" placeholder="请输入结束日期">
                    </div>
                    <div class="layui-inline left">
                        <label class="layui-form-label">发布状态</label>
                        <div class="layui-input-block">
                            <select name="status" lay-search="">
                            	<option value="">发布状态</option>
                                <option value="0">未确认</option>
                                <option value="1">待发布</option>
                                <option value="2">已发布</option>
                            </select>
                        </div>
                    </div>
                    <!--<div class="layui-form-item">-->
                    <!--<label class="layui-form-label">合计</label>-->
                    <!--<div class="layui-input-block">-->
                    <!--<input type="text" name="aggreget" placeholder="请输入合同编号" autocomplete="off" class="layui-input w30">-->
                    <!--</div>-->
                    <!--</div>-->
                </div>
                <div class="layui-btn layui-btn-warm search layui-btn-sm" id="search" lay-submit="" lay-filter="search">
                    <i class="layui-icon">&#xe615;</i>查询
                </div>
            </div>
        </div>
        <div class="content_table">
            <div class="tabbut">
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="getCheckData"><i class="layui-icon">&#xe654;</i>确认</button>
                        <button class="layui-btn layui-btn-sm" lay-event="sendCheckData"><i class="layui-icon">&#xe609;</i>发布</button>
                    </div>

                </script>
            </div>
            <div class="tabTable">
                <table id="demo"  lay-filter="table" lay-data="{id:'idTest'}"></table>
                <div class="layui-table-page fr">
                    <div id="layui-table-page1"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="maTypeTemplet">
    {{#if (d.dataStatus == 0) { }}
    待发布
    {{# }else if(d.dataStatus == 1){ }}
    已确认
    {{# }else if(d.dataStatus == 3){ }}
    已发布
    {{# } }}
</script>
<script src="../../js/common/jquery-1.11.3.min.js"></script>
<script src="../../layui/layui.js"></script>
<script src="../../js/common/navList.js"></script>
<script src="../../js/common/ajax.js"></script>

<script>
    layui.use(['table','form','laydate'], function () {
        var form = layui.form;
        var laydate =  layui.laydate;
        laydate.render({
            elem: '#test31',
            theme: 'grid',
        });
        laydate.render({
            elem: '#test32',
            theme: 'grid',
        });
        //初始化第一个实例
        ajaxTable({
            idNode: '#demo',
            url: 'settlement/getList',
            dataCols: [
                {fixed: true, checkbox: true},
                {field: 'companyName', title: '客户',align: 'center'},
                {field: 'dayForecastAmount', title: '日预测量',align: 'center'},
                {field: ' dayPlanAmount', title: '日计划量',align: 'center'},
                {field: ' dayActualAmount', title: '日实际量',align: 'center'},
                {field: 'price', title: '单价',align: 'center',width:'10%'},
                {field: 'dataStatus', title: '状态',align: 'center',templet:'#maTypeTemplet',width:'10%'},
                {field: 'totalPrice', title: '总价',align: 'center',width:'10%'},
            ],
            successFull:function(res, curr, count,table){
                console.log(res)
                table.on('toolbar(table)', function(obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    if(obj.event == 'getCheckData'){
                        var data = checkStatus.data;
                        if(data.length == ''){
                            layer.msg('请勾选要确认的客户', {
                                icon: 6
                            });
                        }else{
                            var dataId = [];
                            $.each(data,function(i,item){
                                dataId.push(item.id);
                            });
                            ajaxPost({
                                url:'settlement/confirm',
                                data:{
                                    ids:dataId
                                },
                                successFull:function(res){
                                    layer.msg("已成功确认", {
                                        icon: 6
                                    });
                                    updata();
                                },
                                errCallBack:function(res){
                                    layer.msg(res.msg, {
                                        icon: 6
                                    });
                                    updata();
                                }
                            })
                        }
                    };
                    if(obj.event == 'sendCheckData'){
                        var data = checkStatus.data;
                        if(data.length == ''){
                            layer.msg('请勾选要发布的客户', {
                                icon: 6
                            });
                        }else{
                            var senddataId = [];
                            $.each(data,function(i,item){
                                senddataId.push(item.id);
                            });
                            ajaxPost({
                                url:'settlement/release',
                                data:{
                                    ids:senddataId
                                },
                                successFull:function(res){
                                    layer.msg("已成功发布", {
                                        icon: 6
                                    });
                                    updata();
                                },
                                errCallBack:function(res){
                                    layer.msg(res.msg, {
                                        icon: 6
                                    });
                                    updata();
                                }
                            })
                        }
                    }
                });
            }
        });
//        条件查询
        form.on('submit(search)', function(data){
            var urlParme;
            if(data.field.endTime ==''){
                urlParme ='&startTime='+data.field.startTime+'&status='+data.field.status;
            };
            if(data.field.startTime ==''){
                urlParme ='&endTime='+data.field.endTime+'&status='+data.field.status;
            };
            if(data.field.endTime ==''&&data.field.startTime ==''){
                urlParme ='&status='+data.field.status
            };
            ajaxTable({
                idNode: '#demo',
                url: 'settlement/getList',
                urlParme:urlParme,
                dataCols: [
                    {fixed: true, checkbox: true},
                    {field: 'companyName', title: '客户',align: 'center'},
                    {field: 'dayForecastAmount', title: '日预测量',align: 'center'},
                    {field: ' dayPlanAmount', title: '日计划量',align: 'center'},
                    {field: ' dayActualAmount', title: '日实际量',align: 'center'},
                    {field: 'price', title: '单价',align: 'center',width:'10%'},
                    {field: 'dataStatus', title: '状态',align: 'center',templet:'#maTypeTemplet',width:'10%'},
                    {field: 'totalPrice', title: '总价',align: 'center',width:'10%'},
                ],
                successFull: function (res, curr, count) {
                }
            });
        })
    });

    function updata(){
        ajaxTable({
            idNode: '#demo',
            url: 'settlement/getList',
            dataCols: [
                {fixed: true, checkbox: true},
                {field: 'companyName', title: '客户',align: 'center'},
                {field: 'dayForecastAmount', title: '日预测量',align: 'center'},
                {field: ' dayPlanAmount', title: '日计划量',align: 'center'},
                {field: ' dayActualAmount', title: '日实际量',align: 'center'},
                {field: 'price', title: '单价',align: 'center',width:'10%'},
                {field: 'dataStatus', title: '状态',align: 'center',templet:'#maTypeTemplet',width:'10%'},
                {field: 'totalPrice', title: '总价',align: 'center',width:'10%'},
            ]
        })
    }
</script>
</body>
</html>